//
//  CALayer-Extension.swift
//  QQMusic
//
//  Created by xmg on 16/9/7.
//  Copyright © 2016年 wlis. All rights reserved.
//

import UIKit

extension CALayer {
    
    /** 停止动画 */
    func pauseAnimation() {
        let pauseTime = convertTime(CACurrentMediaTime(), fromLayer: nil)
        speed = 0.0
        timeOffset = pauseTime
    }
    /** 继续动画 */
    func resumeAnimation() {
        // 1.取出时间
        let pauseTime = timeOffset
        
        // 2.设置动画的属性
        speed = 1.0
        timeOffset = 0.0
        beginTime = 0.0
        
        // 3.设置开始动画
        let startTime = convertTime(CACurrentMediaTime(), fromLayer: nil) - pauseTime
        beginTime = startTime
    }
}